package com.huaxin.hxmodulesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaxin.hxmodulesystem.dto.ResponseCode;
import com.huaxin.hxmodulesystem.dto.ResponseResult;
import com.huaxin.hxmodulesystem.mapper.SysNationalAllMapper;
import com.huaxin.hxmodulesystem.models.SysNationalAll;
import com.huaxin.hxmodulesystem.service.SysNationalAllService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class SysNationalAllServiceImpl extends ServiceImpl<SysNationalAllMapper, SysNationalAll> implements SysNationalAllService {
    // 根据区域编码查询下级区域
    @Override
    public ResponseResult<List<SysNationalAll>> queryNationalListByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return ResponseResult.failure(ResponseCode.INTERNAL_ERROR, "参数错误！", null);
        }
        QueryWrapper<SysNationalAll> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_code", code);
        return ResponseResult.ok(this.baseMapper.selectList(queryWrapper));
    }

    // 根据区域名称查询区域
    @Override
    public ResponseResult<List<SysNationalAll>> queryNationalListByName(String name) {
        if (StringUtils.isBlank(name)) {
            return ResponseResult.failure(ResponseCode.INTERNAL_ERROR, "参数错误！", null);
        }
        QueryWrapper<SysNationalAll> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("region_name", name);
        return ResponseResult.ok(this.baseMapper.selectList(queryWrapper));
    }

    // 根据区域级别查询区域
    @Override
    public ResponseResult<List<SysNationalAll>> queryNationalListByLevel(Integer level) {
        if (level == null) {
            return ResponseResult.failure(ResponseCode.INTERNAL_ERROR, "参数错误！", null);
        }
        QueryWrapper<SysNationalAll> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("region_level", level);
        return ResponseResult.ok(this.baseMapper.selectList(queryWrapper));
    }
}
